package com.ruoyi.order.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.order.domain.MallOrderItem;
import com.ruoyi.order.mapper.MallOrderItemMapper;
import com.ruoyi.vo.OrderDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.order.mapper.MallOrderMapper;
import com.ruoyi.order.domain.MallOrder;
import com.ruoyi.order.service.IMallOrderService;

/**
 * 订单列表Service业务层处理
 *
 * @author cws
 * @date 2024-11-30
 */
@Service
public class MallOrderServiceImpl implements IMallOrderService {
    @Autowired
    private MallOrderMapper mallOrderMapper;

    @Autowired
    private MallOrderItemMapper mallOrderItemMapper;

    /**
     * 查询订单列表
     *
     * @param id 订单列表主键
     * @return 订单列表
     */
    @Override
    public MallOrder selectMallOrderById(Long id) {
        return mallOrderMapper.selectMallOrderById(id);
    }

    /**
     * 查询订单列表列表
     *
     * @param mallOrder 订单列表
     * @return 订单列表
     */
    @Override
    public List<MallOrder> selectMallOrderList(MallOrder mallOrder) {
        return mallOrderMapper.selectMallOrderList(mallOrder);
    }

    /**
     * 新增订单列表
     *
     * @param mallOrder 订单列表
     * @return 结果
     */
    @Override
    public int insertMallOrder(MallOrder mallOrder) {
        mallOrder.setCreateTime(DateUtils.getNowDate());
        return mallOrderMapper.insertMallOrder(mallOrder);
    }

    /**
     * 修改订单列表
     *
     * @param mallOrder 订单列表
     * @return 结果
     */
    @Override
    public int updateMallOrder(MallOrder mallOrder) {
        return mallOrderMapper.updateMallOrder(mallOrder);
    }

    /**
     * 批量删除订单列表
     *
     * @param ids 需要删除的订单列表主键
     * @return 结果
     */
    @Override
    public int deleteMallOrderByIds(Long[] ids) {
         mallOrderMapper.deleteMallOrderByIds(ids);
//         删除订单item
        mallOrderItemMapper.deleteMallOrderItemByOrderIds(ids);
        return 1;
    }

    /**
     * 删除订单列表信息
     *
     * @param id 订单列表主键
     * @return 结果
     */
    @Override
    public int deleteMallOrderById(Long id) {
        return mallOrderMapper.deleteMallOrderById(id);
    }

    @Override
    public OrderDetailVo showDetail(String id) {
        MallOrder mallOrder = mallOrderMapper.selectMallOrderById(Long.valueOf(id));
        OrderDetailVo orderDetailVo = new OrderDetailVo();
        orderDetailVo.setOrder(mallOrder);
        List<MallOrderItem> orderItemList = mallOrderItemMapper.selectMallOrderItemByOrderSn(mallOrder.getOrderSn());
        orderDetailVo.setOrderItemList(orderItemList);
        return orderDetailVo;
    }
}
